package coroutines.coroutinebuilder

import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking

class AsyncAwaitTest {
}

fun main() {
    runBlocking {
        println("runBlocking() start0")
        val result = asyncAwaitParentStr()
        println("runBlocking() start1")
    }
}

suspend fun asyncAwaitParentStr(): String {
    coroutineScope {
        println("asyncAwaitParentStr() start0")

        val deffer0 = async { asyncAwaitFunc0() }
        val deffer1 = async { asyncAwaitFunc1() }


        deffer0.await()
        deffer1.await()

//        return "asyncAwaitParentStr"
    }

    return "asyncAwaitParentStr"
}

suspend fun asyncAwaitFunc0(): Int {
    println("asyncAwaitFunc0 start0")
    delay(300)
    println("asyncAwaitFunc0 start1")
    return 0
}

suspend fun asyncAwaitFunc1(): Int {
    println("asyncAwaitFunc1 start0")
    delay(400)
    println("asyncAwaitFunc1 start1")
    return 1
}